package com;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class BaseServlet extends HttpServlet{
	
	protected static final String jspHead = Env.get("jsp_root");
	
	public void doGet(HttpServletRequest req, HttpServletResponse res) {
		doPost(req, res);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse res) {
		try {				
			process(req, res);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void response(HttpServletRequest req, HttpServletResponse res, String url){		
		
		try {
			System.out.println(url);
		    RequestDispatcher rd = req.getRequestDispatcher(url);
		    rd.forward(req, res);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected abstract void process(HttpServletRequest req, HttpServletResponse res) throws Exception;
	
	protected static String getJspPath(String fileName) {
		return jspHead + fileName;
	}
	
	
	public void alertLocationHref(HttpServletResponse res, String url, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().alertLocationHref(res, url, msg);
	}

	public void alertResponse(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().alertResponse(res, msg);
	}
	
	public void alertThisReloadResponse(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().alertThisReloadResponse(res, msg);
	}

	public void onlyAlertResponse(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().onlyAlertResponse(res, msg);
	}
	public void alertResponse(HttpServletResponse res, String url, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().alertResponse(res, url, msg);
	}
	public void alertCloseResponse(HttpServletResponse res, String msg) throws IOException{
		BaseServletResponseProcessor.getDefaultInstance().alertCloseResponse(res,msg);
	}
	public void alertPopupCloseResponse(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().alertPopupCloseResponse(res, msg);
	}
	
	public void closePopupResponse(HttpServletResponse res, String url) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().closePopupResponse(res, url);
	}
	
	public void alertThisReload(HttpServletResponse res, String url) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().ThisReloadResponse(res, url);
	}

	public void CloseAndOpenerReloadResponse(HttpServletResponse res) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().CloseAndOpenerReloadResponse(res);
	}

	public void redirect(HttpServletResponse res, String url) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().ThisRedirectResponse(res, url);
	}
	
	public void alertCloseAndOpenerReload(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().OpenerReloadResponse(res, msg);
	}

	public void alertCloseAndTopReload(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().TopReloadResponse(res, msg);
	}
	
	public void alertCloseAndParentReload(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().SelfCloseParentReloadResponse(res, msg);
	}
	
	public void alertAndParentReload(HttpServletResponse res, String msg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().ParentReloadResponse(res, msg);
	}
	
	public void setParentResponse(HttpServletResponse res, String scriptmsg, String bodymsg) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().setParentResponse(res, scriptmsg, bodymsg);
	}
	
	public void closePopupAndOpenerMathodCall(HttpServletResponse res, String msg, String mathodName) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().closePopupAndOpenerMathodCallResponse(res, msg, mathodName);
	}
	
	public void closePopupRedirect(HttpServletResponse res, String msg, String url) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().closePopupRedirect(res, msg, url);
	}
	
	public void openerMathodCallWithParam(HttpServletResponse res,  String mathodWithParam) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().openerMathodCallWithParam(res,mathodWithParam);
	}
	
	public void openerMathodCallWithParamNotDomain(HttpServletResponse res,  String mathodWithParam) throws IOException {
		BaseServletResponseProcessor.getDefaultInstance().openerMathodCallWithParamNotDomain(res,mathodWithParam);
	}
}
